import pygame
from pygame.locals import *
from starsbg import *
from system import System, Planet
from vec2d import Vec2d
from game import Game
from player import Player
from ships.ship import Ship
from compiler.pycodegen import END_FINALLY
from constants import SCREEN_SIZE
from gui.ship import ShipHUD

VERSION = "v0.1 alpha"

pygame.display.init()
# Set up the screen
screen = pygame.display.set_mode((640,640))
# Set the caption
pygame.display.set_caption("Spanky the Conqueror " + VERSION)
# Initialize the Font module
pygame.font.init()



bg = BG()
ship = Ship()
player = Player(ship)
system = System(pos = Vec2d(320,320))
game = Game(player, system)

sun = Planet(pos = Vec2d(5.0,5.0), radius = 70, color = "yellow", mass = 1000000)
planet1 = Planet(pos = Vec2d(6.0,200.0), radius = 15, color = "blue")
planet2 = Planet(pos = Vec2d(6.0,450.0), radius = 25)

system.set_sun(sun)
system.add_planet(planet1)
system.add_planet(planet2)

ship_hud = ShipHUD()

#world_surf = pygame.Surface((SCREEN_SIZE[0] * 10, SCREEN_SIZE[1] * 10))

while True:
    pygame.event.pump()
    game.keys = pygame.key.get_pressed()
    if game.keys[K_ESCAPE]:
        pygame.quit()
        break
    
    # --- Now done in game class ---
    #system.update(game)
    #player.update(game)
    game.update()
    
    # Clear the screen
    screen.fill((0,0,0))
    #world_surf.fill((0,0,0))
    
    # Draw the shnazzy background
    bg.draw(screen, game.player.ship)
    
    # --- Now done in game class ---
    # Draw the solar system
    #system.draw(screen)
    # Draw the player (draws the player's ship aswell)
    #player.draw(screen)
    # ------------------------------
    
    game.draw(screen)
    
    #screen.blit(world_surf, screen.get_rect(), game.player.ship.view_rect)
    
    ship_hud.draw(screen, game.player)
    
    # Update display
    pygame.display.flip()
    #ship.x += 1
    pygame.event.pump()
    